package jdbc;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 在DML 中使用预编译SQL
 *
 * INSERT语句：
 * INSERT　INTO　userinfo (username,password,nickname, age)
 * VALUES (?,?,?,?)
 *
 * UPDATE语句：
 * UPDATE userinfo
 * SET password=?
 * WHERE username=?
 *
 * DELETE 语句：
 * DELETE FROM userinfo
 * WHERE username=?
 */

public class JDBCDemo8 {
    public static void main(String[] args) {
        try (
                Connection connection = DBUtil.getConnection();
        ){

            String sql = "INSERT INTO userinfo (username,password,nickname, age) " +
                         "VALUES (?,?,?,?)";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1,"王克晶");
            preparedStatement.setString(2,"66666");
            preparedStatement.setString(3,"克晶");
            preparedStatement.setInt(4,18);
            int num =  preparedStatement.executeUpdate();
            if (num>0){
                System.out.println("插入成功");
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
